package com.mask.im.business.common.util;

import lombok.extern.slf4j.Slf4j;

import java.time.Duration;

/**
 * @author jian
 */
@Slf4j
public class TimeUtils {

    public static String formatTime(long seconds) {
        Duration duration = Duration.ofSeconds(seconds);
        if (duration.getSeconds() < 60) {
            return duration.getSeconds() + "秒";
        } else if (duration.getSeconds() < 60 * 60) {
            return String.format("%d分%02d", duration.getSeconds() / 60, duration.getSeconds() % 60);
        } else if (duration.getSeconds() < 24 * 60 * 60) {
            return String.format("%d小时", duration.getSeconds() / 60 / 60);
        } else {
            return String.format("%d天", duration.getSeconds() / 24 / 60 / 60);
        }
    }
}
